<?php

require_once ('db_config.php');

session_start();

$name = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$query = "select * from users where name='$name'";
$result = mysql_query($query);
if (mysql_num_rows($result) >= 1) {
    $_SESSION['signup-error'] = "Пользователь с таким именем уже существует";
    header('location: ../login.php#toregister');
    exit();
}
$query = "insert into users(name, email, password) values('$name','$email','$password');";
$result = mysql_query($query);
if ($result) {
    $_SESSION['username'] = $name;
    // TO TEST PAGE
    echo 
    header('Location: http://localhost/miras/test/test.html');
} else {
    $_SESSION['signup-error'] = "Ошибка на сервере!";
    header('Location:../login.php#toregister');
}
?>